package exam.model.dao;

import java.util.HashMap;
import java.util.List;

import exam.common.util.NullCheckUtil;
import exam.model.entity.TStudentEntity;

public class StudentDao extends AbstractDao<TStudentEntity>{
	
	public StudentDao() {
		super(TStudentEntity.class);
	}
	
	public List<TStudentEntity> selectListStudent() {
		return super.selectList("select s from TStudentEntity s inner join s.userEntity");
	}
	
	public TStudentEntity selectByPk(long id) {
		return super.selectByPk(id);
	}
	
	public TStudentEntity selectByCd(String cd) {
		String query = "select s from TStudentEntity s inner join s.userEntity where s.studentCd='" + cd + "'";
		return super.jdbcManager.executeByQuery(query).getSingleResult();
	}
	
	public void insertStudent(TStudentEntity student) {
		super.insert(student);
	}
	
	public void updateStudent(TStudentEntity student) {
			super.update(student);
	}
	
	public boolean deleteStudentByPk(long id) {
		if (NullCheckUtil.isNUll(selectByPk(id))) {
			return false;
		}
		super.delete(id);
		return true;
	}
	
	public int deleteStudentByCd(String cd) {
		String query = "delete from TStudentEntity s where s.studentCd=:studentCd";
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("studentCd", cd);
		return super.jdbcManager.executeByQueryParams(query, params).delete();
	}
	
}
